package com.xiaolin.lang;

/**
 * @ClassName TestClone
 * @Description TODO
 * @Detail 实现cloneable接口来实现克隆
 *              步骤：
 *                  1、编写一个类实现 Cloneable 接口
 *                  2、重写clone方法
 * @Author MyPC
 * @Date 2020/9/26
 * @Version 1.0
 */
public class TestClone {
    public static void main(String[] args) throws CloneNotSupportedException {
        Student s1=new Student();
        s1.setAge(18);
        s1.setName("小李");
        Student clone = (Student) s1.clone();
        System.out.println(clone.getAge());
    }
}


class Student implements Cloneable{
    String name;
    int age;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    protected Object clone() throws CloneNotSupportedException {
        return super.clone();
    }
}
